package com.tongfusoft.document.doc.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.tongfusoft.da.template.service.impl.DataTemplateServiceImpl;
import com.tongfusoft.document.doc.service.IDocAuthenticationService;
import com.tongfusoft.document.entity.DocHistory;
import com.tongfusoft.document.entity.Users;

@Service("docAuthenticationService")
public class DocAuthenticationServiceImpl extends DataTemplateServiceImpl implements IDocAuthenticationService{

	@Override
	public boolean isRead(String groupId, Users user) {
		
		Map map = new HashMap();
		map.put("groupId", groupId);
		map.put("userId", user.getUserId());
		if(StringUtils.isEmpty(groupId)){
			return false;
		}
		
		if(super.selectList("isRead", map).size()>0){
			
			return true;
		}else{
			
			return false;
		}
			
		
		
	}

	@Override
	public boolean isWrite(String groupId, Users user) {
		Map map = new HashMap();
		map.put("groupId", groupId);
		map.put("userId", user.getUserId());
		
		if(StringUtils.isEmpty(groupId)){
			return false;
		}
		if(super.selectList("isWrite", map).size()>0){
			
			return true;
		}else{
			
			return false;
		}
	}

	@Override
	public boolean isDelete(String groupId, Users user) {
		Map map = new HashMap();
		map.put("groupId", groupId);
		map.put("userId", user.getUserId());
		if(StringUtils.isEmpty(groupId)){
			return false;
		}
		
		if(super.selectList("isDelete", map).size()>0){
			
			return true;
		}else{
			
			return false;
		}
	}

	@Override
	public String getGroupId(String docName, String docId) {
		DocHistory dh = new DocHistory();
		dh.setDocName(docName);
		if(StringUtils.isNotEmpty(docId)){
			dh.setDocId(docId);
			return (String)super.selectOne("getDocGroupByDocId", dh);
		}else{
			
			return (String)super.selectOne("getDocGroupByDocName", dh);
		}
	}

}
